﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using EbbinghausWord.Entities;
using System.Linq;

namespace EbbinghausWord.BLL
{
    /// <summary>
    /// 复习管理
    /// </summary>
    public class ReviewManager
    {
        #region private field

        #endregion

        #region public method
        /// <summary>
        /// 获得需要复习的单词
        /// </summary>
        /// <returns></returns>
        public static List<WordEntity> GetReviewWordBook()
        {
            //当前时间-第一次时间 > 用户当前记忆级别+1的 遗忘曲线时间点，说明用户应该学习了
            return WordBookManager.WordBook.Where(x => x.IsInTheWordBook == true &&
                                                     DateTime.Now - x.StartRemeberingDateTime >
                                                     SystemConfig.ForgetTimePoint[x.RememberLevel + 1]).ToList();
        }

        /// <summary>
        /// 将单词添加到单词本
        /// </summary>
        /// <param name="wordEntity"></param>
        public static void AddToWordbook(WordEntity wordEntity)
        {
            //当前单词加入到单词本中
            wordEntity.IsInTheWordBook = true;

            //记录记忆日期
            wordEntity.StartRemeberingDateTime = DateTime.Now;

            //设置单词记忆级别为0
            wordEntity.RememberLevel = 0;
        }

        /// <summary>
        /// 设置单词记忆级别
        /// </summary>
        /// <param name="wordEntity"></param>
        public static void SetWordRemeberLevel(WordEntity wordEntity)
        {
            for (var i = wordEntity.RememberLevel + 1; i < SystemConfig.ForgetTimePoint.Count; i++)
            {
                //当前时间 - 第一次时间 是否大于 某一个最大的记忆级别
                if ((DateTime.Now - wordEntity.StartRemeberingDateTime) > SystemConfig.ForgetTimePoint[i])
                {
                    wordEntity.RememberLevel = i;
                }
                else
                {
                    break;
                }
            }

            //用户是否彻底记住了这个单词
            if (wordEntity.RememberLevel + 1 == SystemConfig.ForgetTimePoint.Count)
            {
                wordEntity.RememberStatus = RememberStatus.Remembered;
            }
        }
        #endregion
    }
}
